<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('财报点评') }}</span>
    </div>
    <el-table v-loading="loading" tooltip-effect="darkTable" :data="pcwReviewList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('点评人')" align="center" prop="createBy">
        <template slot-scope="scope">
          <span>{{ scope.row.createBy.userName }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('点评时间')" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('点评类型')" align="center" prop="reviewType" :formatter="reviewTypeFormat" />
      <el-table-column :label="$t('点评意见')" align="center" prop="remark" show-overflow-tooltip />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-show="userId === scope.row.createBy.id"
            v-hasPermi="['company:pcw:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-show="userId === scope.row.createBy.id"
            v-hasPermi="['company:pcw:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList(undefined)"
    />
    <!-- 财报点评对话框 -->
    <el-dialog :title="$t('财报点评')" :visible.sync="reviewFormOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="reviewDialogForm" append-to-body>
      <pcwReviewForm ref="pcwReviewForm" :company-id="companyId" />
    </el-dialog>

  </div>
</template>

<script>
import { listPcwReview, delPcwReview } from '@/api/company/pcw/pcwReview'
import pcwReviewForm from './pcwReviewForm.vue'
export default {
  components: {
    pcwReviewForm
  },
  props: {
    companyId: {
      type: String,
      required: true
    }
  },
  data() {
      return {
          userId: this.$store.state.user.userId,
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 财报点评表格数据
          pcwReviewList: [],
          // 点评类型字典
          reviewTypeOptions: undefined,
          // 财报点评formOpen
          reviewFormOpen: false,
          // 查询参数
          queryParams: {
              companyId: this.$route.query.companyId,
              mainId: undefined,
              pageNum: 1,
              pageSize: 10
          }
      }
  },
  created() {
      this.getList('')
        this.getDicts('review_type').then(response => {
          this.reviewTypeOptions = response.data
        })
    console.log(this.userId)
  },
  methods: {
    /** 查询财报点评列表 */
    getList(id) {
      this.loading = true
        if (id) {
          this.queryParams.mainId = id
        }
      listPcwReview(this.queryParams).then(response => {
        this.pcwReviewList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 点评类型字典翻译
    reviewTypeFormat(row) {
      return this.selectDictLabel(this.reviewTypeOptions, row.reviewType)
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delPcwReview(row.id)
        }).then(() => {
            this.getList(this.queryParams.mainId)
            this.msgSuccess(this.$t('删除成功'))
            this.$parent.$parent.getList()
        }).catch(function() {
        })
    },
    // 修改财报点评form
    updateHandle(row) {
      this.reviewFormOpen = true
      this.$nextTick(() => {
        this.$refs.pcwReviewForm.init(row)
      })
    }
  }
}
</script>
